﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Gemciler_Uretim.İslemler
{
    public partial class UretimDurumlari : DevExpress.XtraEditors.XtraForm
    {
        public UretimDurumlari()
        {
            InitializeComponent();
        }
        SqlConnecitonClass sqlbaglanti = new SqlConnecitonClass();
        public string miktar,bolum_kodu,bolum_adi,en,boy,ozgul_agirlik,mt_agirlik,kalinlik;
        public Int32 sip_RECno,kul_no;

        private void UretimDurumlari_Load(object sender, EventArgs e)
        {
            text_agirlik.Text = ozgul_agirlik;
            text_boy.Text = boy;
            text_en.Text = en;
            text_mt_ağirlik.Text = mt_agirlik;
            text_kalinlik.Text = kalinlik;



            if (bolum_kodu == "04")
            {

                combo_birim.DataSource = sqlbaglanti.ShowTable("SELECT  bolum_no AS KOD,bolum_adi AS ADI from TK_URT_BOLUM_TANIMLARI where bolum_no in (04)", CommandType.Text);
                combo_birim.ValueMember = "KOD";
                combo_birim.DisplayMember = "ADI";
                combo_birim.SelectedIndex = 0;
                comboBox1.DataSource = sqlbaglanti.ShowTable("SELECT  [drm_durum_no]  AS KOD,[drm_durum_adi] AS ADI  FROM [TK_URT_DURUM_TANIMLARI] WHERE [drm_bolum_kodu]='" + bolum_kodu + "'", CommandType.Text);
                comboBox1.ValueMember = "KOD";
                comboBox1.DisplayMember = "ADI";
            }
            else
            {

                combo_birim.DataSource = sqlbaglanti.ShowTable("SELECT  bolum_no AS KOD,bolum_adi AS ADI from TK_URT_BOLUM_TANIMLARI where bolum_no in (01,02,03)", CommandType.Text);
                combo_birim.ValueMember = "KOD";
                combo_birim.DisplayMember = "ADI";
                combo_birim.SelectedIndex = 0;
                
            }
           
         
           
            
            if (sip_RECno == 0) { Close(); }
            comboBox1.SelectedIndex = 0;
            text_miktar.Text = miktar;
            this.Text = "Üretim Durum Girişi /" + bolum_kodu +"-"+bolum_adi;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (text_miktar.Value > 0)
            {
                string miktar = Convert.ToString(text_miktar.Text);
                miktar = miktar.Replace(",", ".");
                en = text_en.Value.ToString(); 
                boy = text_boy.Value.ToString();
                mt_agirlik = text_mt_ağirlik.Value.ToString();
                ozgul_agirlik = text_agirlik.Value.ToString();
                kalinlik = text_kalinlik.Value.ToString();
                en = en.Replace(",",".");
                boy = boy.Replace(",", ".");
                mt_agirlik = mt_agirlik.Replace(",", ".");
                ozgul_agirlik = ozgul_agirlik.Replace(",", ".");
                kalinlik = kalinlik.Replace(",", ".");

                sqlbaglanti.CommScalar("INSERT INTO [TK_URT_BOLUM_HAREKETLERI]   ([bhrk_sip_RECno],[bhrk_kullanici_kodu]   ,[bhrk_tarih]"
             + ",[bhrk_bolum_kodu] ,bhrk_islem_durumu,[brhk_giris_cikis],[bhrk_tipi],[bhrk_en] ,[bhrk_boy] ,[brhk_ozgul_agirlik]"
             + ",[bhrk_mt_agirlik]     ,[bhrk_miktar],bhrk_aciklama)"
             + " VALUES   (" + sip_RECno + "," + kul_no + ",getdate(),'"+combo_birim.SelectedValue.ToString()+"'," + comboBox1.SelectedValue + ",0,0,"+en+","+boy+","+ozgul_agirlik+","+mt_agirlik+"," + miktar + ",'" + textEdit1.Text + "' )", CommandType.Text);
                MessageBox.Show("KAYIT TAMAMLANDI");
                Close();
            }
            else { MessageBox.Show("MİKTAR GİRİN"); }

        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void combo_birim_SelectedIndexChanged(object sender, EventArgs e)
        {
            string secilen_bolum = combo_birim.SelectedValue.ToString();

            comboBox1.DataSource = sqlbaglanti.ShowTable("SELECT  [drm_durum_no]  AS KOD,[drm_durum_adi] AS ADI  FROM [TK_URT_DURUM_TANIMLARI] WHERE [drm_bolum_kodu]='"+secilen_bolum+"'", CommandType.Text);
            comboBox1.ValueMember = "KOD";
            comboBox1.DisplayMember = "ADI";
           
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}